package org.gourpg.entity.user;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.ToString;
import org.hibernate.proxy.HibernateProxy;

import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.Table;
import java.sql.Date;
import java.util.Objects;

/**
 * 人员配置实体
 */
@Getter
@Setter
@ToString
@RequiredArgsConstructor
@Entity
@Table(name = "person_detail")
public class PersonDetails {
    /**
     * 纯ID，新用户临时生成，主键
     */
    @Id
    private Long id;

    /**
     * 用户名称
     */
    private String personName;

    /**
     * 证件类型（身份证、居住证、通行证）字典 IDTYPE
     */
    private String idType;

    /**
     * 用户状态 （在岗、离岗、请假）字典 PERSON_STATUS
     */
    private String personStatus;

    /**
     * 证件编号
     */
    private String idNumber;

    /**
     * 生日
     */
    private Date birthday;

    /**
     * 用户说明
     */
    private String remark;

    /**
     * 头像路径
     */
    private String logo;

    @Override
    public final boolean equals(Object o) {
        if (this == o) return true;
        if (o == null) return false;
        Class<?> oEffectiveClass = o instanceof HibernateProxy ? ((HibernateProxy) o).getHibernateLazyInitializer().getPersistentClass() : o.getClass();
        Class<?> thisEffectiveClass = this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass() : this.getClass();
        if (thisEffectiveClass != oEffectiveClass) return false;
        PersonDetails that = (PersonDetails) o;
        return getId() != null && Objects.equals(getId(), that.getId());
    }

    @Override
    public final int hashCode() {
        return this instanceof HibernateProxy ? ((HibernateProxy) this).getHibernateLazyInitializer().getPersistentClass().hashCode() : getClass().hashCode();
    }
}
